<!DOCTYPE html>
<html>
<head>
    <title>城市空气质量查询</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Roboto', 'Microsoft YaHei', sans-serif;
        }

        body {
            background: linear-gradient(135deg, #f5f7fa 0%, #c3cfe2 100%);
            min-height: 100vh;
            padding: 2rem;
            display: flex;
            justify-content: center;
            align-items: center;
        }

        .card {
            background: rgba(255, 255, 255, 0.98);
            border-radius: 16px;
            box-shadow: 0 12px 40px rgba(0, 0, 0, 0.12);
            padding: 2.5rem;
            max-width: 800px;
            width: 100%;
            transition: transform 0.3s ease;
            margin: 20px;
        }

        .header {
            text-align: center;
            margin-bottom: 2.5rem;
        }

        .title {
            color: #2c3e50;
            font-size: 2.4rem;
            font-weight: 600;
            margin-bottom: 0.8rem;
            letter-spacing: -0.5px;
        }

        .subtitle {
            color: #7f8c8d;
            font-size: 1.1rem;
            font-weight: 400;
        }

        .search-form {
            margin-bottom: 2rem;
        }

        .form-group {
            display: flex;
            gap: 12px;
            justify-content: center;
        }

        input {
            padding: 12px 20px;
            width: 300px;
            border: 2px solid #e0e6ed;
            border-radius: 8px;
            font-size: 1rem;
            transition: all 0.3s ease;
        }

        input:focus {
            outline: none;
            border-color: #6c5ce7;
            box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.1);
        }

        button {
            padding: 12px 32px;
            background: #6c5ce7;
            color: white;
            border: none;
            border-radius: 8px;
            font-size: 1rem;
            font-weight: 500;
            cursor: pointer;
            transition: all 0.3s ease;
        }

        button:hover {
            background: #5b4bc4;
            transform: translateY(-1px);
        }

        .result-box {
            background: #f8f9fa;
            border-radius: 12px;
            padding: 2rem;
            margin: 2rem 0;
            box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.04);
        }

        .result-header {
            color: #2c3e50;
            font-size: 1.8rem;
            margin-bottom: 1.5rem;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        .aqi-badge {
            display: inline-block;
            padding: 4px 12px;
            border-radius: 20px;
            font-size: 0.9rem;
            font-weight: 500;
        }

        .detail-grid {
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
            gap: 1.5rem;
            margin-top: 1.5rem;
        }

        .detail-item {
            background: rgba(255, 255, 255, 0.9);
            padding: 1.2rem;
            border-radius: 8px;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
        }

        .detail-item h4 {
            color: #7f8c8d;
            font-size: 0.95rem;
            margin-bottom: 8px;
        }

        .detail-item p {
            color: #2c3e50;
            font-size: 1.4rem;
            font-weight: 600;
        }

        .error {
            background: #ffe3e3;
            color: #ff4444;
            padding: 1rem;
            border-radius: 8px;
            margin: 1.5rem 0;
            display: flex;
            align-items: center;
            gap: 10px;
        }

        @media (max-width: 768px) {
            .card {
                padding: 1.5rem;
                margin: 10px;
            }

            .title {
                font-size: 2rem;
            }

            .form-group {
                flex-direction: column;
            }

            input {
                width: 100%;
            }

            button {
                width: 100%;
            }
        }
    </style>
</head>
<body>
    <div class="card">
        <div class="header">
            <h1 class="title">城市空气质量查询</h1>
            <p class="subtitle">精准实时空气质量数据监测</p>
        </div>

        <form method="POST" class="search-form">
            <div class="form-group">
                <input type="text" name="city" placeholder="请输入城市名称" required>
                <button type="submit">立即查询</button>
            </div>
        </form>

        {% if error %}
            <div class="error">
                <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-alert-triangle"><path d="M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"></path><line x1="12" y1="9" x2="12" y2="13"></line><line x1="12" y1="17" x2="12" y2="17"></line></svg>
                {{ error }}
            </div>
        {% endif %}

        {% if result %}
        <div class="result-box">
            <div class="result-header">
                <span>{{ result.city }} 空气质量</span>
                <span class="aqi-badge" style="background: {{ get_aqi_color(result.aqi) }}; color: white;">
                    AQI {{ result.aqi }}
                </span>
            </div>

            <div class="detail-grid">
                <div class="detail-item">
                    <h4>空气质量等级</h4>
                    <p>{{ result.quality }}</p>
                </div>
                <div class="detail-item">
                    <h4>主要污染物</h4>
                    <p>{{ result.primary }}</p>
                </div>
            </div>

            <div class="detail-grid">
                <div class="detail-item">
                    <h4>PM2.5</h4>
                    <p>{{ result.pm2p5 }} μg/m³</p>
                </div>
                <div class="detail-item">
                    <h4>PM10</h4>
                    <p>{{ result.pm10 }} μg/m³</p>
                </div>
                <div class="detail-item">
                    <h4>二氧化硫</h4>
                    <p>{{ result.so2 }} μg/m³</p>
                </div>
                <div class="detail-item">
                    <h4>二氧化氮</h4>
                    <p>{{ result.no2 }} μg/m³</p>
                </div>
                <div class="detail-item">
                    <h4>臭氧</h4>
                    <p>{{ result.o3 }} μg/m³</p>
                </div>
                <div class="detail-item">
                    <h4>一氧化碳</h4>
                    <p>{{ result.co }} mg/m³</p>
                </div>
            </div>
        </div>
        {% endif %}

        <div class="result-box">
            <div class="header">
                <h2 class="title" style="font-size: 1.6rem;">DeepSeek 分析报告</h2>
                <p class="subtitle" style="font-size: 0.95rem;">Generated by DeepSeek R1 Assistant</p>
            </div>
            <div class="detail-item" style="margin-top: 1.5rem;">
                {{ data }}
            </div>
        </div>
    </div>
</body>
</html>